package com.dhy.socket.request.core;

import io.netty.handler.codec.http.DefaultFullHttpResponse;

import java.nio.charset.StandardCharsets;

import static io.netty.handler.codec.http.HttpHeaderNames.CONTENT_LENGTH;

/**
 * @author 大忽悠
 * @create 2022/6/20 20:04
 */
public class ErrorController {

    public void handleError(DhyHttpRequest request, DefaultFullHttpResponse response){
        byte[] res = "<h1>404!!!<h1>".getBytes(StandardCharsets.UTF_8);
        //如果不加响应头标注响应数据长度，浏览器会一直转圈圈等待客户端将剩余数据传输过来
        response.headers().setInt(CONTENT_LENGTH, res.length);
        response.content().writeBytes(res);
    }
}
